<?php

class Importacion_model extends CI_Model {

    function __construct() {
        parent :: __construct();
    }

    function importar_generales() {
        if (!empty($_FILES)) {
            $data = $this->upload->data();
            $tempFile = $data['full_path'];
            $filename = $tempFile;
            $i = 0;
            $fp = fopen($filename, "r") or die("No se puede abrir $filename");
            
            /*while (!feof($fp)) {
                $i++;
                $string = fgets($fp);
                //procesamos cada línea...
                $a['DIST'] = substr($string, 0, 5);
                $a['PROGRAMA'] = substr($string, 5, 12);
                $a['FACU'] = substr($string, 17, 10);
                $a['DFACULTAD'] = substr($string, 27, 100);
                $a['CARR'] = substr($string, 127, 10);
                $a['DCARRERA'] = substr($string, 137, 100);
                $a['MODALIDAD'] = substr($string, 237, 20);
                $a['CAMPUS'] = substr($string, 257, 20);
                $a['NIV'] = substr($string, 277, 4);
                $a['CRED'] = substr($string, 281, 5);
                $a['DUR'] = substr($string, 286, 4);
                $a['EST'] = substr($string, 290, 4);
                $a['NP'] = substr($string, 294, 3);
                if ($i == 1) {
                    // checamos un poco la estructura del encabezado:
                    // todo: agregar mejores criterios
                    if (trim($a['DIST']) <> 'DIST') {
                        return array('tipo' => 'error', 'mensaje' => 'El archivo parece no ser el correcto, por favor verifiquelo...');
                        exit;
                    } else {
                        $this->db->query('TRUNCATE TABLE GENERAL;');
                    }
                }
                if ($i > 1) {
                    $this->db->insert('GENERAL', $a);
                }
            }
            fclose($fp);*/
        }
        return array('tipo' => 'success', 'mensaje' => 'El archivo se procesó con éxito');
    }

    function importar_egresados() {
        if (!empty($_FILES)) {
            $data = $this->upload->data();
            $tempFile = $data['full_path'];
            $filename = $tempFile;
            $i = 0;
            $fp = fopen($filename, "r") or die("No se puede abrir $filename");
            while (!feof($fp)) {
                $i++;
                $string = fgets($fp);
                //procesamos cada línea...
                $a['DIST'] = substr($string, 0, 6);
                $a['PROGRAMA'] = substr($string, 6, 12);
                $a['H<18'] = substr($string, 19, 5);
                $a['H=18'] = substr($string, 25, 5);
                $a['H=19'] = substr($string, 31, 5);
                $a['H=20'] = substr($string, 37, 5);
                $a['H=21'] = substr($string, 43, 5);
                $a['H=22'] = substr($string, 49, 5);
                $a['H=23'] = substr($string, 55, 5);
                $a['H=24'] = substr($string, 61, 5);
                $a['H=25'] = substr($string, 67, 5);
                $a['H=26'] = substr($string, 73, 5);
                $a['H=27'] = substr($string, 79, 5);
                $a['H=28'] = substr($string, 85, 5);
                $a['H=29'] = substr($string, 91, 5);
                $a['H3034'] = substr($string, 97, 5);
                $a['H3539'] = substr($string, 103, 5);
                $a['H>39'] = substr($string, 109, 5);
                $a['TEGH'] = substr($string, 115, 5);
                $a['M<18'] = substr($string, 121, 5);
                $a['M=18'] = substr($string, 127, 5);
                $a['M=19'] = substr($string, 133, 5);
                $a['M=20'] = substr($string, 139, 5);
                $a['M=21'] = substr($string, 145, 5);
                $a['M=22'] = substr($string, 151, 5);
                $a['M=23'] = substr($string, 157, 5);
                $a['M=24'] = substr($string, 163, 5);
                $a['M=25'] = substr($string, 169, 5);
                $a['M=26'] = substr($string, 175, 5);
                $a['M=27'] = substr($string, 181, 5);
                $a['M=28'] = substr($string, 187, 5);
                $a['M=29'] = substr($string, 193, 5);
                $a['M3034'] = substr($string, 199, 5);
                $a['M3539'] = substr($string, 205, 5);
                $a['M>39'] = substr($string, 211, 5);
                $a['TEGM'] = substr($string, 217, 5);
                $a['T<18'] = substr($string, 223, 5);
                $a['T=18'] = substr($string, 229, 5);
                $a['T=19'] = substr($string, 235, 5);
                $a['T=20'] = substr($string, 241, 5);
                $a['T=21'] = substr($string, 247, 5);
                $a['T=22'] = substr($string, 253, 5);
                $a['T=23'] = substr($string, 259, 5);
                $a['T=24'] = substr($string, 265, 5);
                $a['T=25'] = substr($string, 271, 5);
                $a['T=26'] = substr($string, 277, 5);
                $a['T=27'] = substr($string, 283, 5);
                $a['T=28'] = substr($string, 289, 5);
                $a['T=29'] = substr($string, 295, 5);
                $a['T3034'] = substr($string, 301, 5);
                $a['T3539'] = substr($string, 307, 5);
                $a['T>39'] = substr($string, 313, 5);
                $a['TEGT'] = substr($string, 319, 5);
                if ($i == 1) {
                    // checamos un poco la estructura del encabezado:
                    // todo: agregar mejores criterios
                    if (trim($a['DIST']) <> 'DIST') {
                        return array('tipo' => 'error', 'mensaje' => 'El archivo parece no ser el correcto, por favor verifiquelo...');
                        exit;
                    } else {
                        $this->db->query('TRUNCATE TABLE EGRESO;');
                    }
                    if ($i > 1) {
                        $this->db->insert('EGRESO', $a);
                    }
                }
                fclose($fp);
            }
        }
        return array('tipo' => 'success', 'mensaje' => 'El archivo se procesó con éxito');
    }

    function importar_ingreso() {
        if (!empty($_FILES)) {
            $data = $this->upload->data();
            $tempFile = $data['full_path'];
            $filename = $tempFile;
            $i = 0;
            $fp = fopen($filename, "r") or die("No se puede abrir $filename");
            while (!feof($fp)) {
                $i++;
                $string = fgets($fp);
                //procesamos cada línea...
                $a['DIST'] = substr($string, 0, 6);
                $a['PROGRAMA'] = substr($string, 6, 12);
                $a['NIH'] = substr($string, 19, 5);
                $a['NIM'] = substr($string, 25, 5);
                $a['TNI1'] = substr($string, 31, 5);
                $a['NHP2'] = substr($string, 37, 5);
                $a['NMP2'] = substr($string, 43, 5);
                $a['TNI2'] = substr($string, 49, 5);
                $a['LOFE'] = substr($string, 55, 5);
                $a['SOLH'] = substr($string, 61, 5);
                $a['SOLM'] = substr($string, 67, 5);
                $a['TSOL'] = substr($string, 73, 5);
                $a['B1'] = substr($string, 79, 5);
                $a['B2'] = substr($string, 85, 5);
                $a['B3'] = substr($string, 91, 5);
                $a['B4'] = substr($string, 97, 5);
                $a['B5'] = substr($string, 103, 5);
                $a['B6'] = substr($string, 109, 5);
                $a['B7'] = substr($string, 115, 5);
                $a['B8'] = substr($string, 121, 5);
                $a['B9'] = substr($string, 127, 5);
                $a['B10'] = substr($string, 133, 5);
                $a['B11'] = substr($string, 139, 5);
                $a['B12'] = substr($string, 145, 5);
                $a['B13'] = substr($string, 151, 5);
                $a['B14'] = substr($string, 157, 5);
                $a['B15'] = substr($string, 163, 5);
                $a['B16'] = substr($string, 169, 5);
                $a['B17'] = substr($string, 175, 5);
                $a['B18'] = substr($string, 181, 5);
                $a['B19'] = substr($string, 187, 5);
                $a['B20'] = substr($string, 193, 5);
                $a['B21'] = substr($string, 199, 5);
                $a['B22'] = substr($string, 205, 5);
                $a['B23'] = substr($string, 211, 5);
                $a['B24'] = substr($string, 217, 5);
                $a['B25'] = substr($string, 223, 5);
                $a['B26'] = substr($string, 229, 5);
                $a['B27'] = substr($string, 235, 5);
                $a['B28'] = substr($string, 241, 5);
                $a['B29'] = substr($string, 247, 5);
                $a['B30'] = substr($string, 253, 5);
                $a['B31'] = substr($string, 259, 5);
                $a['B32'] = substr($string, 265, 5);
                $a['BEU'] = substr($string, 271, 5);
                $a['BCA'] = substr($string, 277, 5);
                $a['BCC'] = substr($string, 283, 5);
                $a['BSU'] = substr($string, 289, 5);
                $a['BAF'] = substr($string, 295, 5);
                $a['BAS'] = substr($string, 301, 5);
                $a['BEU'] = substr($string, 307, 5);
                $a['BOC'] = substr($string, 313, 5);
                $a['TBAC'] = substr($string, 319, 5);
                $a['N30'] = substr($string, 325, 5);
                $a['ND30'] = substr($string, 331, 5);
                $a['N157'] = substr($string, 337, 5);
                $a['NC28'] = substr($string, 343, 5);
                $a['NCC'] = substr($string, 349, 5);
                $a['NSU'] = substr($string, 355, 5);
                $a['NAF'] = substr($string, 361, 5);
                $a['NAS'] = substr($string, 367, 5);
                $a['NEU'] = substr($string, 373, 5);
                $a['NOC'] = substr($string, 379, 5);
                $a['TNAC'] = substr($string, 385, 5);
                $a['<18H'] = substr($string, 391, 5);
                $a['=18H'] = substr($string, 397, 5);
                $a['=19H'] = substr($string, 403, 5);
                $a['=20H'] = substr($string, 409, 5);
                $a['=21H'] = substr($string, 415, 5);
                $a['=22H'] = substr($string, 421, 5);
                $a['=23H'] = substr($string, 427, 5);
                $a['=24H'] = substr($string, 433, 5);
                $a['=25H'] = substr($string, 439, 5);
                $a['=26H'] = substr($string, 445, 5);
                $a['=27H'] = substr($string, 451, 5);
                $a['=28H'] = substr($string, 457, 5);
                $a['=29H'] = substr($string, 463, 5);
                $a['30_4H'] = substr($string, 469, 5);
                $a['35_9H'] = substr($string, 475, 5);
                $a['>39H'] = substr($string, 481, 5);
                $a['TNIH'] = substr($string, 487, 5);
                $a['<18M'] = substr($string, 493, 5);
                $a['=18M'] = substr($string, 499, 5);
                $a['=19M'] = substr($string, 505, 5);
                $a['=20M'] = substr($string, 511, 5);
                $a['=21M'] = substr($string, 517, 5);
                $a['=22M'] = substr($string, 523, 5);
                $a['=23M'] = substr($string, 529, 5);
                $a['=24M'] = substr($string, 535, 5);
                $a['=25M'] = substr($string, 541, 5);
                $a['=26M'] = substr($string, 547, 5);
                $a['=27M'] = substr($string, 553, 5);
                $a['=28M'] = substr($string, 559, 5);
                $a['=29M'] = substr($string, 565, 5);
                $a['30_4M'] = substr($string, 571, 5);
                $a['35_9M'] = substr($string, 577, 5);
                $a['>39M'] = substr($string, 583, 5);
                $a['TNIM'] = substr($string, 589, 5);
                $a['T<18'] = substr($string, 595, 5);
                $a['T=18'] = substr($string, 601, 5);
                $a['T=19'] = substr($string, 607, 5);
                $a['T=20'] = substr($string, 613, 5);
                $a['T=21'] = substr($string, 619, 5);
                $a['T=22'] = substr($string, 625, 5);
                $a['T=23'] = substr($string, 631, 5);
                $a['T=24'] = substr($string, 637, 5);
                $a['T=25'] = substr($string, 643, 5);
                $a['T=26'] = substr($string, 649, 5);
                $a['T=27'] = substr($string, 655, 5);
                $a['T=28'] = substr($string, 661, 5);
                $a['T=29'] = substr($string, 667, 5);
                $a['T30_4'] = substr($string, 673, 5);
                $a['T35_9'] = substr($string, 679, 5);
                $a['T+39'] = substr($string, 685, 5);
                $a['TNIT'] = substr($string, 691, 5);
                if ($i == 1) {
                    // checamos un poco la estructura del encabezado:
                    // todo: agregar mejores criterios
                    if (trim($a['DIST']) <> 'DIST') {
                        return array('tipo' => 'error', 'mensaje' => 'El archivo parece no ser el correcto, por favor verifiquelo...');
                        exit;
                    } else {
                        $this->db->query('TRUNCATE TABLE INGRESO;');
                    }
                }
                if ($i > 1) {
                    $this->db->insert('INGRESO', $a);
                }
            }
            fclose($fp);
        }
        return array('tipo' => 'success', 'mensaje' => 'El archivo se procesó con éxito');
    }

    function importar_permanencia() {
        if (!empty($_FILES)) {
            $data = $this->upload->data();
            $tempFile = $data['full_path'];
            $filename = $tempFile;
            $i = 0;
            $fp = fopen($filename, "r") or die("No se puede abrir $filename");
            while (!feof($fp)) {
                $i++;
                $string = fgets($fp);
                //procesamos cada línea...
                $a['DIST'] = substr($string, 0, 6);
                $a['PROGRAMA'] = substr($string, 6, 12);
                $a['PRIM'] = substr($string, 19, 5);
                $a['SEGU'] = substr($string, 25, 5);
                $a['TERC'] = substr($string, 31, 5);
                $a['CUAR'] = substr($string, 37, 5);
                $a['QUIN'] = substr($string, 43, 5);
                $a['SEXT'] = substr($string, 49, 5);
                $a['SEPT'] = substr($string, 55, 5);
                $a['OCTA'] = substr($string, 61, 5);
                $a['NOVE'] = substr($string, 67, 5);
                $a['DECI'] = substr($string, 73, 5);
                $a['TAVA'] = substr($string, 79, 5);
                $a['A1DH'] = substr($string, 85, 5);
                $a['A2DH'] = substr($string, 91, 5);
                $a['A3DH'] = substr($string, 97, 5);
                $a['A4DH'] = substr($string, 103, 5);
                $a['A5DH'] = substr($string, 109, 5);
                $a['A6DH'] = substr($string, 115, 5);
                $a['A7DH'] = substr($string, 121, 5);
                $a['A8DH'] = substr($string, 127, 5);
                $a['A9DH'] = substr($string, 133, 5);
                $a['A10DH'] = substr($string, 139, 5);
                $a['TADH'] = substr($string, 145, 5);
                $a['A1DM'] = substr($string, 151, 5);
                $a['A2DM'] = substr($string, 157, 5);
                $a['A3DM'] = substr($string, 163, 5);
                $a['A4DM'] = substr($string, 169, 5);
                $a['A5DM'] = substr($string, 175, 5);
                $a['A6DM'] = substr($string, 181, 5);
                $a['A7DM'] = substr($string, 187, 5);
                $a['A8DM'] = substr($string, 193, 5);
                $a['A9DM'] = substr($string, 199, 5);
                $a['A10DM'] = substr($string, 205, 5);
                $a['TADM'] = substr($string, 211, 5);
                $a['A1DT'] = substr($string, 217, 5);
                $a['A2DT'] = substr($string, 223, 5);
                $a['A3DT'] = substr($string, 229, 5);
                $a['A4DT'] = substr($string, 235, 5);
                $a['A5DT'] = substr($string, 241, 5);
                $a['A6DT'] = substr($string, 247, 5);
                $a['A7DT'] = substr($string, 253, 5);
                $a['A8DT'] = substr($string, 259, 5);
                $a['A9DT'] = substr($string, 265, 5);
                $a['A10DT'] = substr($string, 271, 5);
                $a['TADT'] = substr($string, 277, 5);
                $a['<18H'] = substr($string, 283, 5);
                $a['=18H'] = substr($string, 289, 5);
                $a['=19H'] = substr($string, 295, 5);
                $a['=20H'] = substr($string, 301, 5);
                $a['=21H'] = substr($string, 307, 5);
                $a['=22H'] = substr($string, 313, 5);
                $a['=23H'] = substr($string, 319, 5);
                $a['=24H'] = substr($string, 325, 5);
                $a['=25H'] = substr($string, 331, 5);
                $a['=26H'] = substr($string, 337, 5);
                $a['=27H'] = substr($string, 343, 5);
                $a['=28H'] = substr($string, 349, 5);
                $a['=29H'] = substr($string, 355, 5);
                $a['30_4H'] = substr($string, 361, 5);
                $a['35_9H'] = substr($string, 367, 5);
                $a['>39H'] = substr($string, 373, 5);
                $a['TREH'] = substr($string, 379, 5);
                $a['<18M'] = substr($string, 385, 5);
                $a['=18M'] = substr($string, 391, 5);
                $a['=19M'] = substr($string, 397, 5);
                $a['=20M'] = substr($string, 403, 5);
                $a['=21M'] = substr($string, 409, 5);
                $a['=22N'] = substr($string, 415, 5);
                $a['=23M'] = substr($string, 421, 5);
                $a['=24M'] = substr($string, 427, 5);
                $a['=25M'] = substr($string, 433, 5);
                $a['=26M'] = substr($string, 439, 5);
                $a['=27M'] = substr($string, 445, 5);
                $a['=28M'] = substr($string, 451, 5);
                $a['=29M'] = substr($string, 457, 5);
                $a['30_4M'] = substr($string, 463, 5);
                $a['35_9M'] = substr($string, 469, 5);
                $a['>39M'] = substr($string, 475, 5);
                $a['TREM'] = substr($string, 481, 5);
                $a['T<18'] = substr($string, 487, 5);
                $a['T=18'] = substr($string, 493, 5);
                $a['T=19'] = substr($string, 499, 5);
                $a['T=20'] = substr($string, 505, 5);
                $a['T=21'] = substr($string, 511, 5);
                $a['T=22'] = substr($string, 517, 5);
                $a['T=23'] = substr($string, 523, 5);
                $a['T=24'] = substr($string, 529, 5);
                $a['T=25'] = substr($string, 535, 5);
                $a['T=26'] = substr($string, 541, 5);
                $a['T=27'] = substr($string, 547, 5);
                $a['T=28'] = substr($string, 553, 5);
                $a['T=29'] = substr($string, 559, 5);
                $a['T30_4'] = substr($string, 565, 5);
                $a['T35_9'] = substr($string, 571, 5);
                $a['T+39M'] = substr($string, 577, 5);
                $a['TRET'] = substr($string, 583, 5);
                $a['HDIS'] = substr($string, 589, 5);
                $a['MDIS'] = substr($string, 595, 5);
                $a['TDIS'] = substr($string, 601, 5);



                if ($i == 1) {
                    // checamos un poco la estructura del encabezado:
                    // todo: agregar mejores criterios
                    if (trim($a['DIST']) <> 'DIST') {
                        return array('tipo' => 'error', 'mensaje' => 'El archivo parece no ser el correcto, por favor verifiquelo...');
                        exit;
                    } else {
                        $this->db->query('TRUNCATE TABLE PERMANENCIA;');
                    }
                }
                if ($i > 1) {
                    $this->db->insert('PERMANENCIA', $a);
                }
            }
            fclose($fp);
        }
        return array('tipo' => 'success', 'mensaje' => 'El archivo se procesó con éxito');
    }

    function importar_titulados() {
        if (!empty($_FILES)) {
            $data = $this->upload->data();
            $tempFile = $data['full_path'];
            $filename = $tempFile;
            $i = 0;
            $fp = fopen($filename, "r") or die("No se puede abrir $filename");
            while (!feof($fp)) {
                $i++;
                $string = fgets($fp);
                //procesamos cada línea...
                $a['DIST'] = substr($string, 0, 2);
                $a['PROGRAMA'] = substr($string, 2, 12);
                $a['M_MENOS18'] = substr($string, 19, 5);
                $a['F_MENOS18'] = substr($string, 25, 5);
                $a['S<18'] = substr($string, 31, 5);
                $a['M_18'] = substr($string, 37, 5);
                $a['F_18'] = substr($string, 43, 5);
                $a['S18'] = substr($string, 49, 5);
                $a['M_19'] = substr($string, 55, 5);
                $a['F_19'] = substr($string, 61, 5);
                $a['S19'] = substr($string, 67, 5);
                $a['M_20'] = substr($string, 73, 5);
                $a['F_20'] = substr($string, 79, 5);
                $a['S20'] = substr($string, 85, 5);
                $a['M_21'] = substr($string, 91, 5);
                $a['F_21'] = substr($string, 97, 5);
                $a['S21'] = substr($string, 103, 5);
                $a['M_22'] = substr($string, 109, 5);
                $a['F_22'] = substr($string, 115, 5);
                $a['S22'] = substr($string, 121, 5);
                $a['M_23'] = substr($string, 127, 5);
                $a['F_23'] = substr($string, 133, 5);
                $a['S23'] = substr($string, 139, 5);
                $a['M_24'] = substr($string, 145, 5);
                $a['F_24'] = substr($string, 151, 5);
                $a['S24'] = substr($string, 157, 5);
                $a['M_25'] = substr($string, 163, 5);
                $a['F_25'] = substr($string, 169, 5);
                $a['S25'] = substr($string, 175, 5);
                $a['M_26'] = substr($string, 181, 5);
                $a['F_26'] = substr($string, 187, 5);
                $a['S26'] = substr($string, 193, 5);
                $a['M_27'] = substr($string, 199, 5);
                $a['F_27'] = substr($string, 205, 5);
                $a['S27'] = substr($string, 211, 5);
                $a['M_28'] = substr($string, 217, 5);
                $a['F_28'] = substr($string, 223, 5);
                $a['S28'] = substr($string, 229, 5);
                $a['M_29'] = substr($string, 235, 5);
                $a['F_29'] = substr($string, 241, 5);
                $a['S29'] = substr($string, 247, 5);
                $a['M_3034'] = substr($string, 253, 5);
                $a['F_3034'] = substr($string, 259, 5);
                $a['S3034'] = substr($string, 265, 5);
                $a['M_3539'] = substr($string, 271, 5);
                $a['F_3539'] = substr($string, 277, 5);
                $a['S3539'] = substr($string, 283, 5);
                $a['M_39OMAS'] = substr($string, 289, 5);
                $a['F_39OMAS'] = substr($string, 295, 5);
                $a['S>39'] = substr($string, 301, 5);
                $a['TTIM'] = substr($string, 307, 5);
                $a['TTIF'] = substr($string, 313, 5);
                $a['TOTAL'] = substr($string, 319, 5);

                if ($i == 1) {
                    // checamos un poco la estructura del encabezado:
                    // todo: agregar mejores criterios
                    if (trim($a['DIST']) <> 'DI') {
                        return array('tipo' => 'error', 'mensaje' => 'El archivo parece no ser el correcto, por favor verifiquelo...');
                        exit;
                    } else {
                        $this->db->query('TRUNCATE TABLE TITULADOS;');
                    }
                }
                if ($i > 1) {
                    $this->db->insert('TITULADOS', $a);
                }
            }
            fclose($fp);
        }
        return array('tipo' => 'success', 'mensaje' => 'El archivo se procesó con éxito');
    }

    function importar_pobla() {
        if (!empty($_FILES)) {
            $data = $this->upload->data();
            $tempFile = $data['full_path'];
            $filename = $tempFile;
            $i = 0;
            $fp = fopen($filename, "r") or die("No se puede abrir $filename");
            while (!feof($fp)) {
                $i++;
                $string = fgets($fp);
                //procesamos cada línea...
                $a['DIST'] = substr($string, 0, 6);
                $a['PROGRAMA'] = substr($string, 6, 12);
                $a['M_MENOS18'] = substr($string, 19, 5);
                $a['F_MENOS18'] = substr($string, 25, 5);
                $a['S<18'] = substr($string, 31, 5);
                $a['M_18'] = substr($string, 37, 5);
                $a['F_18'] = substr($string, 43, 5);
                $a['S18'] = substr($string, 49, 5);
                $a['M_19'] = substr($string, 55, 5);
                $a['F_19'] = substr($string, 61, 5);
                $a['S19'] = substr($string, 67, 5);
                $a['M_20'] = substr($string, 73, 5);
                $a['F_20'] = substr($string, 79, 5);
                $a['S20'] = substr($string, 85, 5);
                $a['M_21'] = substr($string, 91, 5);
                $a['F_21'] = substr($string, 97, 5);
                $a['S21'] = substr($string, 103, 5);
                $a['M_22'] = substr($string, 109, 5);
                $a['F_22'] = substr($string, 115, 5);
                $a['S22'] = substr($string, 121, 5);
                $a['M_23'] = substr($string, 127, 5);
                $a['F_23'] = substr($string, 133, 5);
                $a['S23'] = substr($string, 139, 5);
                $a['M_24'] = substr($string, 145, 5);
                $a['F_24'] = substr($string, 151, 5);
                $a['S24'] = substr($string, 157, 5);
                $a['M_25'] = substr($string, 163, 5);
                $a['F_25'] = substr($string, 169, 5);
                $a['S25'] = substr($string, 175, 5);
                $a['M_26'] = substr($string, 181, 5);
                $a['F_26'] = substr($string, 187, 5);
                $a['S26'] = substr($string, 193, 5);
                $a['M_27'] = substr($string, 199, 5);
                $a['F_27'] = substr($string, 205, 5);
                $a['S27'] = substr($string, 211, 5);
                $a['M_28'] = substr($string, 217, 5);
                $a['F_28'] = substr($string, 223, 5);
                $a['S28'] = substr($string, 229, 5);
                $a['M_29'] = substr($string, 235, 5);
                $a['F_29'] = substr($string, 241, 5);
                $a['S29'] = substr($string, 247, 5);
                $a['M_3034'] = substr($string, 253, 5);
                $a['F_3034'] = substr($string, 259, 5);
                $a['S3034'] = substr($string, 265, 5);
                $a['M_3539'] = substr($string, 271, 5);
                $a['F_3539'] = substr($string, 277, 5);
                $a['S3539'] = substr($string, 283, 5);
                $a['M_39OMAS'] = substr($string, 289, 5);
                $a['F_39OMAS'] = substr($string, 295, 5);
                $a['S>39'] = substr($string, 301, 5);
                $a['TTIM'] = substr($string, 307, 5);
                $a['TTIF'] = substr($string, 313, 5);
                $a['TOTAL'] = substr($string, 319, 5);

                if ($i == 1) {
                    // checamos un poco la estructura del encabezado:
                    // todo: agregar mejores criterios
                    if (trim($a['DIST']) <> 'DIST') {
                        return array('tipo' => 'error', 'mensaje' => 'El archivo parece no ser el correcto, por favor verifiquelo...');
                        exit;
                    } else {
                        $this->db->query('TRUNCATE TABLE POBLA;');
                    }
                }
                if ($i > 1) {
                    $this->db->insert('POBLA', $a);
                }
            }
            fclose($fp);
        }
        return array('tipo' => 'success', 'mensaje' => 'El archivo se procesó con éxito');
    }

}
